// 外部插入
$("#Nav").load("html/nav.html");
$("#Bottom").load("html/bottom.html");
$("#Dalunbo").load("html/bigcarousel.html");
 $("#Xiaolunbo").load("html/xiaolunbo.html");


// 全局变量
 let str1 = "";

// 商品接口

// 接口数据
$(function () {
  // 上模板
  for (let i = 0; i < 10; i++) {
    $.ajax({
      type: "get",
      url: "http://jx.xuzhixiang.top/ap/api/productlist.php",
      data: { uid: 74661 },
      success: function (data) {
        foo(data);
        $(".FloorModule-box").html(str);
      },
    });
  }
  let str = "";
  function foo(data) {
    let random = Math.floor(Math.random() * 9);

    str += `
        <div class="General FloorModule--tmcsContentItem--c31nDTr">
            <a href="http://localhost:8080/html/details.html?id=${data.data[random].pid}">
              <img
                src="${data.data[random].pimg}">
              <div class="FloorModule--mask--26Ahf9Q"></div>
              <div class="FloorModule--tmcsName--19MBfMf">${data.data[random].pdesc}</div><span
                class="rax-text-v2 FloorModule--tmcsPrice--1dbgcpg">￥${data.data[random].pprice}</span>
            </a></div>
        `;
  }
  
  // 下模板
  $.ajax({
    type: "get",
    url: "http://jx.xuzhixiang.top/ap/api/productlist.php",
    data: { uid: 74661 },
    success: function (data) {
      foo1(data);
    },
  });
  function foo1(data) {
    for (let i = 0; i < 10; i++) {
      let random = Math.floor(Math.random() * 9);
      str1 += `
            <div class="General Wonderful--WonderfulItem--22oI0pH">
            <a href="http://localhost:8080/html/details.html?id=${data.data[random].pid}">
                  <img src="${data.data[random].pimg}">
                    <div class="Wonderful--mask--1fwB7tp"></div>
                    <p class="Wonderful--title--23U6SgE">${data.data[random].pdesc}</p>
                    <p class="Wonderful--price--2VEZvrl">￥${data.data[random].pprice}</p>
                  </a></div>
            `;
    }
    $(".Wonderful-box2").html(str1);
  }
});




//   用户接口
function getUrlmessag() {
  let test = window.location.search;//?pid=609037
  test = test.slice(1).split("&");
  let urlObj = {};
  test.forEach(item => {
    let arr = item.split("=");
    urlObj[arr[0]] = arr[1];
  });
  return urlObj;
}
const urlObj2 = getUrlmessag();

if (urlObj2.id != undefined) {
  $('.VipContent--userText--3fYu5Ba').text('欢迎您' + urlObj2.id);
}

// 搜索接口
$(function () {
  $('.search-criteria').click(function () {
    window.location.replace(url = 'http://localhost:8080/html/list.html')
  })
})



// 瀑布流

  $(document).scroll(function () {
    let t1=$(".FloorModule--tmcsModule--27mV5Wq").outerHeight();
    let t2=$(".Wonderful--WonderfulTop--bh-vw_R").outerHeight();
    // console.log($(document).scrollTop(), $(".FloorModule--tmcsModule--27mV5Wq").outerHeight(),$(".Wonderful--WonderfulTop--bh-vw_R").outerHeight());
 if($(document).scrollTop()>(t1+t2)&&$(document).scrollTop()<4000){
  Jiazai()
 }

})


function Jiazai(){
  $.ajax({
    type: "get",
    url: "http://jx.xuzhixiang.top/ap/api/productlist.php",
    data: { uid: 74661 },
    success: function (data) {
      foo1(data);
    },
  });
  function foo1(data) {
    for (let i = 0; i < 10; i++) {
      let random = Math.floor(Math.random() * 9);
      str1 += `
            <div class="General Wonderful--WonderfulItem--22oI0pH">
            <a href="http://localhost:8080/html/details.html?id=${data.data[random].pid}">
                  <img src="${data.data[random].pimg}">
                    <div class="Wonderful--mask--1fwB7tp"></div>
                    <p class="Wonderful--title--23U6SgE">${data.data[random].pdesc}</p>
                    <p class="Wonderful--price--2VEZvrl">￥${data.data[random].pprice}</p>
                  </a></div>
            `;
    }
    $(".Wonderful-box2").html(str1);
  }
}